home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 11
/
FM Towns Free Software Collection 11.iso
/
t_os
/
tool
/
zc
/
src
/
word.c
< prev
next >
Wrap
Text File
|
1995-06-30
|
2KB
|
121 lines
#include <stdio.h>
main()
{
char rbuf[80],text[160], tmp[80];
char *textp, *cutp;
unsigned int textlen, cutlen, ret_code, i;
FILE *fp;
fp = fopen("dat","r");
while(fgets(rbuf, 80, fp)){
memset( text, 0, sizeof(text));
Norm_line( rbuf, text);
textp = text;
textlen=strlen(text) - 1; /* 改行記号は無視 */
printf("-------------------\nInput = %s,len=%u \n",textp,textlen);
i = 1;
ret_code = 0;
while(ret_code == 0 ){ /* テキスト終まで */
ret_code = Get_word(&textp, &textlen, &cutp, &cutlen);
if( ret_code == -2 || ret_code == -10){ /* デミリタばかり */
break;
}
memcpy(tmp, cutp, cutlen);
tmp[cutlen] = 0;
printf("%u: word=%s len = %u next=%s nextlen=%u\n",i,tmp,cutlen, textp,textlen);
i++;
}
}
fclose(fp);
return;
}
/***************************************************************************
単語きりだし
**************************************************************************/
int Get_word( textp, textlen, wordp, wordlen )
char **textp;
unsigned int *textlen;
char **wordp;
unsigned int *wordlen;
{
unsigned int len, len2;
char *top, *btm;
len = *textlen;
top = *textp;
if( (len == 0) || (top == NULL) ){
return(-10); /* パラメータエラー */
}
while( len > 0){
if( *top != ' ' ){
break;
}
top ++;
len --;
}
*wordp = top;
btm = top;
len2 = 0;
while( len > 0){
if( *btm == ' ' ){
break;
}
btm ++;
len --;
len2 ++;
}
*wordlen = len2;
*textp = btm;
*textlen = len;
if(top == btm){
return(-2); /* デミリタばかり(テキスト終) */
}
if(len == 0){
return(-1); /* テキスト終 */
}else{
return(0); /* 次がある */
}
}
/***************************************************************************
文字列正規化
**************************************************************************/
int Norm_line(intext, outtext)
char *intext;
char *outtext;
{
int len;
char c;
len=strlen(intext);
while(len > 0){
switch(*intext){
case ')':
case ',':
*outtext = ' ';
break;
case ';':
*outtext = ' ';
*outtext ++;
default:
*outtext = *intext;
break;
}
outtext ++;
intext ++;
len --;
}
return;
}